file(GLOB_RECURSE _FL_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc")

if(NOT ENABLE_CPU OR WIN32)
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/apply_momentum_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/aggregation_kernel_factory.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/dense_grad_accum_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/fed_avg_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/sgd_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/optimizer_kernel_factory.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/round_kernel_factory.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/round_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/start_fl_job_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/update_model_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/get_model_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/pull_weight_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/push_weight_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/client_list_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/exchange_keys_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/get_keys_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/get_secrets_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/reconstruct_secrets_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/share_secrets_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/push_list_sign_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/get_list_sign_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/round/push_metrics_kernel.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/kernel/params_info.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/consistent_hash_ring.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/iteration_timer.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/local_meta_store.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/memory_register.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/parameter_aggregator.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/executor.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/collective_ops_impl.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/distributed_count_service.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/distributed_metadata_store.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/iteration.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/model_store.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/round.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/server.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/cert_verify.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/server_recovery.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "server/iteration_metrics.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "worker/fl_worker.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "armour/secure_protocol/encrypt.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "armour/secure_protocol/key_agreement.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "armour/secure_protocol/masking.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "armour/secure_protocol/secret_sharing.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "armour/cipher/cipher_init.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "armour/cipher/cipher_keys.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "armour/cipher/cipher_meta_storage.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "armour/cipher/cipher_reconstruct.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "armour/cipher/cipher_shares.cc")
    list(REMOVE_ITEM _FL_SRC_FILES "armour/cipher/cipher_unmask.cc")
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-tautological-pointer-compare")
endif()

list(LENGTH _FL_SRC_FILES fl_file_num)
if(NOT fl_file_num EQUAL 0)
    set_property(SOURCE ${_FL_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_FL)
    add_library(_mindspore_fl_obj OBJECT ${_FL_SRC_FILES})
    target_link_libraries(_mindspore_fl_obj mindspore::flatbuffers)
endif()
